<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_actions_AjaxAddLangToWebsiteAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$values = $this->getFormValues("form");		
		
		$rootNodeId = m_website_documents_Website::getRootNodeId();
		
		$rootNode = f_document_Provider::getInstance()->getByModelAndUniqueId('website/RootNode', $rootNodeId);
		$website = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Website', $this->getRequestParameter("docId"));
				
		$rootNodeTranslated = f_document_Provider::getInstance()->getByModelAndUniqueId('website/RootNode', $rootNodeId, $values["iso"]);
		$websiteTranslated = f_document_Provider::getInstance()->getByModelAndUniqueId('website/Website', $this->getRequestParameter("docId"), $values["iso"]);		
		
		$rootNodeTranslated->setLabel($rootNode->getLabel())->save();
		
		$websiteTranslated	->setAuthor($this->getUser()->getLogin())
							->setLabel($website->getLabel()." (".strtoupper($values["iso"]).")")
							->setUrl($website->getUrl()."/".strtolower($values["iso"]))
							->setPublicationstatus("DRAFT")
							->save();
		
		$rootNodeTranslated->addWebsite($websiteTranslated)->save();
	}	
	
	public function validate()
	{
		return $this->getUserContext()->hasRight(array("backoffice_accessBo", "website_Translation"));
	}
}